﻿using CommunityToolkit.Mvvm.ComponentModel;
using Microsoft.Extensions.DependencyInjection;
using Prism.Mvvm;
using ProductionLine.Modules.ShareLib.Helpers;
using ProductionLine.Modules.ShareLib.Models;
using ScottPlot;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace ProductionLine.Modules.Chart.Views {


    /// <summary>
    /// ChartView.xaml 的交互逻辑
    /// </summary>
    /// 

    public partial class ChartView : UserControl, INotifyPropertyChanged {

        public event PropertyChangedEventHandler PropertyChanged;

        // 使用CallerMemberName特性简化代码
        protected void OnPropertyChanged([CallerMemberName] string propertyName = null) {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }

        private ScadaReadData _scadaReadDataProp;
        /// <summary>
        /// SCADA数据
        /// </summary>
        public ScadaReadData ScadaReadDataProp {
            get { return _scadaReadDataProp; }
            set { _scadaReadDataProp = value;
                OnPropertyChanged();
            }
        }


        public ChartView(GlobalConfig globalConfig) {
            InitializeComponent();
            _scadaReadDataProp = globalConfig.ScadaReadDataProp;

            #region 陶化ph值
            // 设置一个记录器，该记录器将随着数据的添加而增长
            var logger = WpfPlotShow.Plot.Add.DataLogger();

            // 模拟实时数据流
            int j = 10;
            Task.Run(async () => {
                for (int x = 1; x <= j; x++) {
                    logger.Add(x, _scadaReadDataProp.PhosphatingPhValue);
                    if (x == j) {
                        j += 10;
                    }

                    WpfPlotShow.Refresh();
                    await Task.Delay(100);

                }
            });
            #endregion

            #region 脱脂压力值
            // 设置一个记录器，该记录器将随着数据的添加而增长
            var logger1 = WpfPlotShow1.Plot.Add.DataLogger();

            // 模拟实时数据流
            int k = 10;
            Task.Run(async () => {
                for (int x = 1; x <= k; x++) {
                    logger1.Add(x, _scadaReadDataProp.DegreasingSprayPumpPressure);
                    if (x == k) {
                        k += 10;
                    }

                    WpfPlotShow1.Refresh();
                    await Task.Delay(100);

                }
            });
            #endregion

            #region 脱脂ph值
            // 设置一个记录器，该记录器将随着数据的添加而增长
            var logger2 = WpfPlotShow2.Plot.Add.DataLogger();

            // 模拟实时数据流
            int l = 10;
            Task.Run(async () => {
                for (int x = 1; x <= l; x++) {
                    logger2.Add(x, _scadaReadDataProp.DegreasingPhValue);
                    if (x == l) {
                        l += 10;
                    }

                    WpfPlotShow2.Refresh();
                    await Task.Delay(100);

                }
            });
            #endregion

            #region 粗洗喷淋泵压力值
            // 设置一个记录器，该记录器将随着数据的添加而增长
            var logger3 = WpfPlotShow3.Plot.Add.DataLogger();

            // 模拟实时数据流
            int m = 10;
            Task.Run(async () => {
                for (int x = 1; x <= m; x++) {
                    logger3.Add(x, _scadaReadDataProp.RoughWashSprayPumpPressure);
                    if (x == m) {
                        m += 10;
                    }

                    WpfPlotShow3.Refresh();
                    await Task.Delay(100);

                }
            });
            #endregion

        }

    }
}
